package org.apache.ibatis.transaction;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * Wraps a database connection.
 * Handles the connection lifecycle that comprises: its creation, preparation, commit/rollback and close.
 *(处理连接生命周期，包括：创建、准备、提交/回滚和关闭)
 *
 * @author Clinton Begin
 */
public interface Transaction {

    /**
     * Retrieve inner database connection
     * 获取对应的数据库连接对象
     *
     * @return DataBase connection
     * @throws SQLException
     */
    Connection getConnection() throws SQLException;

    /**
     * Commit inner database connection.
     * 提交事务
     *
     * @throws SQLException
     */
    void commit() throws SQLException;

    /**
     * Rollback inner database connection.
     * 回滚事务
     *
     * @throws SQLException
     */
    void rollback() throws SQLException;

    /**
     * Close inner database connection.
     * 关闭数据库连接
     *
     * @throws SQLException
     */
    void close() throws SQLException;

    /**
     * Get transaction timeout if set
     * 获取事务超时时间
     *
     * @throws SQLException
     */
    Integer getTimeout() throws SQLException;

}
